package com.itqf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itqf.bean.DtsUser;
import com.itqf.dto.DtsSearchDto;
import com.itqf.mapper.DtsUserMapper;
import com.itqf.service.DtsUserService;
import com.itqf.vo.DayStatis;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * projectName: shop_manage
 *
 * @author: MaTianWei
 * time: 2021/7/14 18:08
 * description:
 */
@Service
public class DtsUserServiceImpl implements DtsUserService {
    @Autowired
    private DtsUserMapper dtsUserMapper;
    public static final Logger logger = LoggerFactory.getLogger(DtsUserServiceImpl.class);
    //指定日期内，用户的增长量
    @Override
    public List<DayStatis> queryDayUser(int days) {

        if(days <= 0){

            logger.error("[用户增长业务]指定每天查询天数不能小于0");

            return null;
        }
        List<DayStatis> dayStatis = dtsUserMapper.queryDay(days);

        logger.info("[用户增长业务]业务调用完毕查询指定日期:{},用户增长数据为:{}",days,dayStatis);

        return dayStatis;
    }





    //会员分页查询
    @Override
    public Map findUserByPage(DtsSearchDto userDto) {
        logger.info("[管理员查询]业务开始调用获取数据为:{}",userDto);
        //1·分页插件启动
        PageHelper.startPage(userDto.getPage(),userDto.getLimit());
        //2·数据库查询
        List<DtsUser> adminList = dtsUserMapper.queryUserByPage(userDto);
        //3·pageInfo封装
        PageInfo<DtsUser> pageInfo = new PageInfo<>(adminList);
        //4·封装返回结果数据
        Map data = new HashMap();
        data.put("total",pageInfo.getTotal());
        data.put("items",pageInfo.getList());
        logger.info("[会员查询]业务调用完毕,获取数据为:{}",data);
        return data;
    }



    //用户统计
    @Override
    public List<Map> querRows() {
        List<Map> maps = dtsUserMapper.queryRows();
        return maps;
    }
}
